|
|
|
|
|
|
|
Listing 9.15. Coding the cmdCreateTable_Click event. |
|
|
|
|
|
|
|
|
Private Sub cmdCreateTable_Click()
'
' create a new table in a database
'
On Error Resume Next
'
Dim ws As Workspace
Dim db As Database
Dim td As TableDef
Dim fl As Field
Dim pr As Property
'
Dim strDBName As String
Dim strTDName As String
Dim strFLName As String
Dim intFLType As Integer
Dim strMsg As String
'
' init values
strDBName = App.Path & "\NewDB.mdb"
strTDName = "NewTable"
strFLName = "NewField"
intFLType = dbText
'
' erase db if it's there
Kill strDBName
'
' open ws and create db
Set ws = DBEngine.Workspaces(0)
Set db = ws.CreateDatabase(strDBName, dbLangGeneral, dbVersion30)
'
' create a new table
Set td = db.CreateTableDef(strTDName)
'
' create a new field in table
Set fl = td.CreateField(strFLName, intFLType)
'
' add new objects to collections
td.Fields.Append fl
db.TableDefs.Append td
'
' now show new table properties
On Error GoTo LocalErr
strMsg = ""
For Each pr In td.Properties
strMsg = strMsg & pr.Name
strMsg = strMsg & " = "
strMsg = strMsg & pr.Value
strMsg = strMsg & " {"
strMsg = strMsg & ShowType(pr.Type) & "}"
strMsg = strMsg & vbCrLf
Next
' |
|
|
|
|
|